<template>
    <el-container>
        <el-main class="wrapper">
            <v-breadcrumb v-bind:breadcumb="breadcumb"></v-breadcrumb>
            <section class="panel" :style="{height: mainHeight+'px'}">
                <div class="panel-body">
                    <div class="btn-group" style="margin-bottom: 15px">
                        <el-button @click="list" type="primary" icon="fa fa-refresh"
                                   size="small"> 刷新
                        </el-button>
                    </div>
                    <el-table v-loading="loading"
                              element-loading-text="努力加载中..."
                              element-loading-spinner="el-icon-loading"
                              :data="tableData"
                              :border="true" style="width: 100%">
                        <el-table-column prop="total" label="库存"></el-table-column>
                        <el-table-column prop="usable" label="可推送"></el-table-column>
                        <el-table-column prop="added" label="今日新增"></el-table-column>
                    </el-table>
                    <el-table v-loading="loading"
                              element-loading-text="努力加载中..."
                              element-loading-spinner="el-icon-loading"
                              :data="tableLog"
                              :border="true" style="width: 100%">
                        <el-table-column prop="title" label="标题" width="300px"></el-table-column>
                        <el-table-column prop="template_id" label="模板ID"></el-table-column>
                        <el-table-column prop="number" label="发送数量" width="300px"></el-table-column>
                        <el-table-column prop="total" label="预推送总量" width="300px"></el-table-column>
                        <el-table-column prop="created_at" label="开始时间" width="200px"></el-table-column>
                        <el-table-column prop="updated_at" label="结束时间" width="200px"></el-table-column>
                    </el-table>
                </div>
            </section>
        </el-main>
    </el-container>
</template>
<script>
    import {mapGetters} from 'vuex';
    import vBreadcrumb from '../layout/breadcrumb.vue';
    import {FormIDList} from '../../utils/axios';
    export default {
        components:{vBreadcrumb},
        data(){
            return {
                breadcumb:[{name: "FormID"}],
                updateDialogTile:'',
                updateDialog:false,
                tableData:[],
                tableLog:[],
                option: {
                    size: 1,
                    full: false,
                    outputType: 'png',
                    canMove: true,
                    fixedBox: true,
                    autoCrop: true,
                    autoCropWidth: 360,
                    autoCropHeight: 204,
                    original: false,
                    canMoveBox: true
                },
            }
        },
        activated(){
            this.$store.dispatch('setActive', '/formid');
            this.list();
            this.previews =  {};
        },
        computed: {
            ...mapGetters(['active','mainHeight','loading','upload']),
            myHeaders(){
                var token = this.$storage.get('token');
                return {
                    Authorization:token.token_type+' ' + token.access_token,
                    Accept:'application/json'
                }
            },
        },
        methods:{
            //获取列表
            list(){
                this.$store.dispatch('setLoading', true);
                FormIDList().then((response)=>{
                    if (response.code) {
                        this.$message.error(response.msg);
                    } else {
                        this.$store.dispatch('setLoading', false);
                        this.tableData = response.data.list;
                        this.tableLog = response.data.log;
                    }
                })
            },
        },
        filters: {
            channel: function (val,data) {
                if (!val) return '';
                let name = '';
                data.filter((item)=>{
                    if(item.id === val){
                        name = item.name;
                    }
                });
                return name;
            }
        }
    }
</script>
